angular.module('calendarcontrollers',[])
  //发现的首页（约局）的Controller
  .controller('CalendarCtrl',function($scope,$state,Storage,Meeting,Calendar,LBS){
    "use strict";

    var lastSelectMonth = new Date();
    var memberId = '';
    var cityId = 0;
    $scope.options = {
      defaultDate: new Date(),
      minDate: "1970-01-01",
      maxDate: "4040-12-31",
      dayNamesLength: 1,
      meetingCount:0,
      mondayIsFirstDay: false,
      eventClick: function(date) {
      },
      dateClick: function(date) {
        var dateTime = formatDate(date.date);
        Storage.set("dateTime",dateTime);
        var weekDay= getWeekDay(new Date(dateTime));//获取到周日历的信息
        Meeting.getActivityByDay(memberId,formatDate(date.date),cityId,$scope.options.city_name);
        Calendar.getCalendar(weekDay,'dayActivity',memberId,cityId,$scope.options.city_name);
        $state.go("day-activity");

      },
      changeMonth: function(month, year) {
        var selectMonth = month.name;
        var date = new Date(year+"-"+selectMonth);
        lastSelectMonth = date;
        Calendar.getMonthActivity(date,memberId,cityId,$scope.options.city_name);
      },
      filteredEventsChange: function(filteredEvents) {
      }
    };
    //$scope.events = [];
    $scope.$on('$ionicView.beforeEnter', function(){
      memberId = Storage.get('member').member_id;
      if(Storage.get("lbsCity")&& Storage.get("lbsCity")!=null && Storage.get("lbsCity")!=''){
        var lbsCity = Storage.get("lbsCity");
        $scope.options.city_name=lbsCity.city_name;
        cityId = lbsCity.shop_city_id;
      }else{
        $scope.options.city_name = '广州市';
      }
      Calendar.getMonthActivity(lastSelectMonth,memberId,cityId,$scope.options.city_name);
    })

    $scope.events = [];

    $scope.$on('Calendar.getMonthActivityUpdated',function(){
      $scope.events = Calendar.getMonthActivityJson().monthActivity;
      $scope.options.meetingCount = Calendar.getMonthActivityJson().monthActivityCount;
    });
  })
